<?php
// Error Reporting
error_reporting(E_ALL);

// Security
ini_set('register_globals', 'Off');

/*if (ini_get('register_globals')) {
	exit('Error: register_globals is enabled!');
}
*/
// Configuration
require('admin/config.php');

// Page Time
$time = (time() + microtime());

// Locator
require(DIR_LIBRARY . 'locator.php');
$locator =& new Locator();

// Config
$config =& $locator->get('config');

// Database
$database =& $locator->get('database');

// Settings
$settings = $database->getRows("select * from setting where type = 'admin' or type = 'global'");

foreach ($settings as $setting) {
	$config->set($setting['key'], $setting['value']);
}

// Language
$language =& $locator->get('language');

// Template
$template =& $locator->get('template');

// Character Set
$template->set('charset', $language->get('charset'));

// Text Direction
$template->set('direction', $language->get('direction'));

// Language Code
$template->set('code', $language->get('code'));

// Base URL
if (@$_SERVER['HTTPS'] != 'on') {
	$template->set('base', HTTP_SERVER);
} else {
	$template->set('base', HTTPS_SERVER);
}

// Request
$request =& $locator->get('request');

// Response
$response =& $locator->get('response');

// Controller
$controller =& $locator->get('controller');

// Controller Directory
$controller->setDirectory(DIR_CONTROLLER);

// Default Controller
$controller->setDefault('home', 'index');

// Error Controller
$controller->setError('error', 'index');

// Login
$controller->addPreAction('login', 'isLogged');

// Permission
//$controller->addPreAction('permission', 'hasPermission');

// Dispatch
$controller->dispatch($request);

// Output
$response->output();

// Parse Time
if ($config->get('config_parse_time')) {
	echo($language->get('text_time', round((time() + microtime()) - $time, 4)));
}
?>